<template>
  <div>
    <el-form ref="postForm" :model="postForm" label-width="80px">
      <el-form-item label="信息类型">
        <el-select v-model="postForm.type" placeholder="请选择信息类型" style="width:200px">
          <el-option label="私发" value="private"></el-option>
          <el-option label="公告" value="public"></el-option>
        </el-select>
      </el-form-item>
        <el-form-item label="接收者">
          <el-input v-model="postForm.receiveUid" style="width: 200px;"></el-input>
        </el-form-item>
      <el-form-item label="信息内容">
        <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="postForm.content" maxlength="100" show-word-limit style="width: 500px;"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">发布</el-button>
        <el-button type="reset" @click="resetForm()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
      return {
        postForm: {
          type: '',
          receiveUid:0,
          content: ''
        },
        messageText:{
          type:'',
          content:'' 
        }
      }
    },
    methods: {
      onSubmit() {
        this.messageText.type=this.postForm.type
        this.messageText.content=this.postForm.content
        //发送请求
        this.$axios.post("/message/post/"+this.postForm.receiveUid,this.messageText).then(res=>{
          if(res.data.status=="SUCCESS"){
            this.$message("发布成功！"),
            this.resetForm()
          }
        })
      },
      //重置
      resetForm(){
        Object.assign(this.$data.postForm,this.$options.data().postForm)
      }
    },

}
</script>

<style>

</style>